package com.cli.springboottemplateengine.engine;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class TemplateEngineRegistry {

    private final Map<String, TemplateEngine> engineMap = new HashMap<>();

    @Autowired
    public TemplateEngineRegistry(List<TemplateEngine> engines) {
        for (TemplateEngine engine : engines) {
            engineMap.put(engine.getType().toLowerCase(), engine);
        }
    }

    public TemplateEngine getEngine(String type) {
        TemplateEngine engine = engineMap.get(type.toLowerCase());
        if (engine == null) {
            throw new IllegalArgumentException("不支持的模板类型: " + type);
        }
        return engine;
    }
}
